package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.Aspect.UserPer;
import com.mc.read.adminapi.manager.BooksManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/14 10:10
 */
@Service
@Slf4j
public class BooksService {
    @Autowired
    BooksManager booksManager;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询书籍类型 selectBookType
     **/
    @UserPer(permission = "book:booktype:select")
    @UserLog(operateName = "查询书籍类型", type = 4)
    public BaseRespose selectBookType(BaseRequest baseRequest) {
        log.info("查询书籍类型,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.selectBookType(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询书籍类型 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询书籍类型 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 添加书籍类型 addBookType
     **/
    @UserPer(permission = "book:booktype:add")
    @UserLog(operateName = "添加书籍类型", type = 1)
    public BaseRespose addBookType(BaseRequest baseRequest) {
        log.info("添加书籍类型,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.addBookType(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("添加书籍类型 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加书籍类型 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除书籍类型 deleteBookType
     **/
    @UserPer(permission = "book:booktype:del")
    @UserLog(operateName = "删除书籍类型", type = 2)
    public BaseRespose deleteBookType(BaseRequest baseRequest) {
        log.info("删除书籍类型,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.deleteBookType(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("删除书籍类型 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除书籍类型 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 选择书籍类型 chooseBookType
     **/
    public BaseRespose chooseBookType(BaseRequest baseRequest) {
        log.info("选择书籍类型,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose=booksManager.chooseBookType(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("选择书籍类型 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("选择书籍类型 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询书籍列表 selectBookList
     **/
    @UserPer(permission = "book:book:select")
    @UserLog(operateName = "查询书籍列表", type = 4)
    public BaseRespose selectBookList(BaseRequest baseRequest) {
        log.info("查询书籍列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.selectBookList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询书籍列表 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询书籍列表 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询书籍标签 selectBookLabel
     **/
    @UserPer(permission = "book:book:selectBookLabel")
    @UserLog(operateName = "查询书籍标签", type = 4)
    public BaseRespose selectBookLabel(BaseRequest baseRequest) {
        log.info("查询书籍标签,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.selectBookLabel(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询书籍标签 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询书籍标签 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除书籍标签 deleteBooklabel
     **/
    @UserPer(permission = "book:book:delBookLabel")
    @UserLog(operateName = "删除书籍标签", type = 2)
    public BaseRespose deleteBooklabel(BaseRequest baseRequest) {
        log.info("删除书籍标签,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.deleteBooklabel(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("删除书籍标签 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除书籍标签 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 修改书籍信息 updateBookInfo
     **/
    @UserPer(permission = "book:book:updateBookInfo")
    @UserLog(operateName = "修改书籍信息", type = 3)
    public BaseRespose updateBookInfo(BaseRequest baseRequest) {
        log.info("修改书籍信息,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.updateBookInfo(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("修改书籍信息 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改书籍信息 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 添加书籍 addBook
     **/
    @UserPer(permission = "book:book:add")
    @UserLog(operateName = "添加书籍", type = 1)
    public BaseRespose addBook(BaseRequest baseRequest) {
        log.info("添加书籍,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.addBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("添加书籍 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加书籍 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除书籍 deleteBook
     **/
    @UserPer(permission = "book:book:del")
    @UserLog(operateName = "删除书籍", type = 2)
    public BaseRespose deleteBook(BaseRequest baseRequest) {
        log.info("删除书籍,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.deleteBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("删除书籍 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除书籍 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 添加书籍标签 addBookLabel
     **/
    @UserPer(permission = "book:book:addBookLabel")
    @UserLog(operateName = "添加书籍标签", type = 1)
    public BaseRespose addBookLabel(BaseRequest baseRequest) {
        log.info("添加书籍标签,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.addBookLabel(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("添加书籍标签 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加书籍标签 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 书籍审核列表 selectBookAuditList
     **/
    @UserPer(permission = "book:book:selectBookAuditList")
    @UserLog(operateName = "书籍审核列表", type = 4)
    public BaseRespose selectBookAuditList(BaseRequest baseRequest) {
        log.info("书籍审核列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.selectBookAuditList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("书籍审核列表 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("书籍审核列表 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 书籍审核 不通过 bookAuditNoPass
     **/
    @UserPer(permission = "book:book:bookAuditNoPass")
    @UserLog(operateName = "书籍审核 不通过", type = 5)
    public BaseRespose bookAuditNoPass(BaseRequest baseRequest) {
        log.info("书籍审核 不通过,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.bookAuditNoPass(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("书籍审核 不通过 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("书籍审核 不通过 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 书籍审核 通过 bookAuditPass
     **/
    @UserPer(permission = "book:book:bookAuditPass")
    @UserLog(operateName = "书籍审核 通过", type = 5)
    public BaseRespose bookAuditPass(BaseRequest baseRequest) {
        log.info("书籍审核 通过,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.bookAuditPass(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("书籍审核 通过 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("书籍审核 通过 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除书籍审核记录 deleteBookAudit
     **/
    @UserPer(permission = "book:book:bookAuditDel")
    @UserLog(operateName = "删除书籍审核记录", type = 2)
    public BaseRespose deleteBookAudit(BaseRequest baseRequest) {
        log.info("删除书籍审核记录,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = booksManager.deleteBookAudit(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("删除书籍审核记录 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除书籍审核记录 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }


}
